package com.example.springbott.wx_service;

import com.example.springbott.bean.MarketBrand;
import com.example.springbott.bean.MarketBrandExample;
import com.example.springbott.bean.zeng.WxBrandDetailVo;
import com.example.springbott.mapper.MarketBrandMapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
/**
 * @author: zeng
 * @Description:
 * @date:
 */
@Service
public class WXBrandServiceImpl implements WXBrandService {
    @Autowired
    MarketBrandMapper marketBrandMapper;
    @Override
    public MarketBrand detail(Integer id) {
        return marketBrandMapper.selectByPrimaryKey(id);
    }

    @Override
    public WxBrandDetailVo list(Integer page, Integer limit) {
        PageHelper.startPage(page, limit);

        MarketBrandExample marketBrandExample = new MarketBrandExample();
        MarketBrandExample.Criteria criteria = marketBrandExample.createCriteria();
        criteria.andDeletedEqualTo(false);
        List<MarketBrand> marketBrands = marketBrandMapper.selectByExample(marketBrandExample);
        // PageInfo marketBrandPageInfo = new PageInfo(marketBrands);
        PageInfo<MarketBrand> marketBrandPageInfo = new PageInfo<>(marketBrands);
        WxBrandDetailVo wxBrandDetailVo = new WxBrandDetailVo();
        wxBrandDetailVo.setList(marketBrands);
        wxBrandDetailVo.setPages(marketBrandPageInfo.getPages());
        wxBrandDetailVo.setPage(page);
        wxBrandDetailVo.setLimit(limit);
        wxBrandDetailVo.setTotal((int) marketBrandPageInfo.getTotal());
        return wxBrandDetailVo;
    }
}
